// eventBus.js
import { reactive } from 'vue';

const eventBus = reactive({
  events: {}
});

eventBus.$on = (event, callback) => {
  if (!eventBus.events[event]) {
    eventBus.events[event] = [];
  }
  eventBus.events[event].push(callback);
};

eventBus.$emit = (event, data) => {
  if (eventBus.events[event]) {
    eventBus.events[event].forEach(callback => callback(data));
  }
};

eventBus.$off = (event, callback) => {
  if (eventBus.events[event]) {
    eventBus.events[event] = eventBus.events[event].filter(cb => cb !== callback);
  }
};

export default eventBus;
